//
//  IndexRecord.m
//  SimulacraDB
//
//  Created by Andre Cohen on 8/15/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "IndexRecord.h"


@implementation IndexRecord

@synthesize rid;

- (id)init {
	[super init];
	return self;
}

+ (id)createWithRID:(RID *)rid {
	IndexRecord *record = [[[IndexRecord alloc] init] autorelease];
	[record setRid:rid];
	return record;
}

+ (IndexRecord *)createFromRecord:(Record *)record {
	return [IndexRecord createWithRID:[[record wrapper] rid]];
}

- (id)initWithCoder:(NSCoder *)coder {
	[super init];
	//NSLog(@"Decode: %d",[coder decodeInt64ForKey:@"rid"]);
	rid = [RID createWithValue:[coder decodeInt64ForKey:@"rid"]];
	[rid setValue:[coder decodeInt64ForKey:@"rid"]];
	return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
	NSLog(@"Encoding: %@ %d",[rid description],[rid value]);
	[coder encodeInt64:[rid value] forKey:@"rid"];
}

- (Record *)toRecordOfType:(Record *)prototype {
	Record *r = [prototype clone];
	[[r wrapper] setRid:rid];
	return r;
}

- (NSString *)description {
	return [rid description];
}

- (BOOL)lessThan:(IndexRecord *)record {
	return [rid value]<[[record rid] value];
}
- (BOOL)greaterThan:(IndexRecord *)record {
	return [rid value]>[[record rid] value];
}
- (BOOL)equalTo:(IndexRecord *)record {
	return [rid value]==[[record rid] value];
}

@end
